<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/1/4 0004
  Time: 13:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>白名单</title>
    <jsp:include page="/commons/common-js.jsp"></jsp:include>
</head>
<body>

<table class="layui-hide" id="whitelisttable" lay-filter="whitelisttable"></table>

<script type="text/html" id="addwhitelist">
    <div class="layui-inline">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    </div>
</script>

<script type="text/html" id="delwhitelist">
    <button class="layui-btn layui-btn-xs" lay-event="del">删除</button>
</script>
<script>
    layui.use(['table', 'form', 'laytpl'], function () {
        var table = layui.table,
            form = layui.form,
            laytpl = layui.laytpl

        var tableins = table.render({
            elem: '#whitelisttable'
            , url: '/sys/whitelist'
            , defaultToolbar: []
            , toolbar: '#addwhitelist'
            , cols: [[
                {field: 'gid', width: 130, title: '标识'}
                ,{field: 'utils', width: 60, toolbar:'#delwhitelist',title: '删除'}
            ]]
            , height: '760',
        });


        //头工具栏事件
        table.on('toolbar(whitelisttable)', function(obj){
            switch(obj.event){
                case 'add' :
                    //页面层
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['200px', '150px'], //宽高
                        content: '<div style="padding: 20px 0 0 20px"><input class="layui-input" style="width: 150px;height: auto" id="addinput" value=""></div>',
                        btn:['保存','取消'],
                        yes:function (index,layero) {
                            var val = $("#addinput").val()
                            if (val){
                                $.ajax({
                                    url:"/sys/addwhitelist/"+val,
                                    success:function(res){
                                        layer.msg(res.msg);
                                        tableins.reload();
                                        layer.close(index);
                                    }
                                })
                            }
                            layer.close(index);
                        },
                        no:function (index,layero) {
                            layer.close(index);
                        }
                    });
                    break;
            };
        });

        //行工具栏事件
        table.on('tool(whitelisttable)', function(obj){

            switch(obj.event){
                case 'del' :
                    obj.data.gid
                    $.ajax({
                        url:"/sys/delwhitelist/"+obj.data.gid,
                        success:function(res){
                            layer.msg(res.msg);
                            tableins.reload();
                        }
                    })
                    break;
            };
        });

    });

</script>

</body>
</html>
